package itsm.isperp.module.controller.incident;

import itsm.isperp.framework.core.context.ContextHolder;
import itsm.isperp.framework.domain.IUser;
import itsm.isperp.framework.web.controller.BaseController;
import itsm.isperp.framework.web.response.ResultMessage;
import itsm.isperp.module.entity.incident.IcdMajorChat;
import itsm.isperp.module.service.incident.IcdMajorChatService;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 控制器
 * 
 * @author lizx
 * @date 2016-11-28 09:29incident
 */
@Controller
@RequestMapping("incident/incident/majorChat")
public class IcdMajorChatController extends BaseController<IcdMajorChat> {

	@Autowired
	protected IcdMajorChatService icdMajorChatService;

	@Override
	public IcdMajorChatService getService() {
		return this.icdMajorChatService;
	}

	@Override
	public String getPageTitle() {
		return "重要事件";
	}

	@RequestMapping("listByIncidentId")
	@ResponseBody
	public List<IcdMajorChat> listByIncidentId(String incidentId,
			int lastId) {
		return this.getService().findByIncidentId(incidentId,lastId);
	}

	@RequestMapping("sendChat")
	@ResponseBody
	public ResultMessage sendChat(String incidentId, String contents) {

		IUser user = ContextHolder.getLoginUser();
		IcdMajorChat chat = new IcdMajorChat();

		chat.setContents(contents);
		chat.setSendTime(new Timestamp(new Date().getTime()));
		chat.setSender(user.getUsername());
		chat.setSenderName(user.getFullname());
		chat.setIncidentId(incidentId);
		this.getService().saveOrUpdate(chat);
		return ResultMessage.success(chat);
	}

}
